package com.example.mobile2030606148tdh0117hw;

import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity2 extends AppCompatActivity {

    private TextView tvMaintitle2;
    private EditText editTextTextPersonName;
    private EditText editTextTextPersonName2;
    private EditText editTextTextPersonName3;
    private Button btnMaincancel;
    private Button btnMainqueding;
    MySQLiteOpenHelper openHelper;
    SQLiteDatabase database;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        initView();
        openHelper = new MySQLiteOpenHelper(this, "factory.db", null, 1);
        btnMaincancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity2.this, MainActivity.class);
                startActivity(intent);
            }
        });
        btnMainqueding.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i("TAG","onClick");
                String name=editTextTextPersonName.getText().toString().trim();
                String skill=editTextTextPersonName2.getText().toString().trim();
                int money=Integer.valueOf(editTextTextPersonName3.getText().toString().trim());
                ContentValues values=new ContentValues();
                values.put("name",name);
                values.put("skill",skill);
                values.put("money",money);
                database=openHelper.getWritableDatabase();
                database.insert("staff",null,values);
                database.close();
                Log.i("TAG",name+"  "+skill+"  "+money);
                Intent intent = new Intent(MainActivity2.this, MainActivity.class);
                startActivity(intent);
            }
        });
    }

    private void initView() {
        tvMaintitle2 = (TextView) findViewById(R.id.tvMaintitle2);
        editTextTextPersonName = (EditText) findViewById(R.id.editTextTextPersonName);
        editTextTextPersonName2 = (EditText) findViewById(R.id.editTextTextPersonName2);
        editTextTextPersonName3 = (EditText) findViewById(R.id.editTextTextPersonName3);
        btnMaincancel = (Button) findViewById(R.id.btnMaincancel);
        btnMainqueding = (Button) findViewById(R.id.btnMainqueding);
    }
}